import request from '@/utils/request'
import type { ApiResponse, User } from '@/types/api'

// 上传用户头像
export function uploadUserAvatar(userId: number, file: File) {
  const formData = new FormData()
  formData.append('file', file)
  
  return request<ApiResponse<{ avatarHash: string }>>({
    url: `/api/user/${userId}/avatar`,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: formData
  })
}

// 获取用户头像URL
export function getUserAvatarUrl(hash: string): string {
  if (!hash) return ''
  // @ts-ignore
  const baseUrl = import.meta.env.VITE_API_BASE_URL || ''
  return `${baseUrl}/api/avatar/${hash}`
} 